#!/bin/sh
# ccnfileproxy
# 
# Part of the CCNx distribution.
#
# Copyright (C) 2009 Palo Alto Research Center, Inc.
#
# This work is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the
# Free Software Foundation.
# This work is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
JAR_FILE=ccn.jar
JAVA_HOME=${JAVA_HOME:=/usr}
JAVA=$JAVA_HOME/bin/java
SCRIPT_DIR=`dirname $0`  # note this is relative path
CMD_NAME=`basename $0` 
CCN_HOME=${CCN_HOME:-$SCRIPT_DIR}
if [ ! -f "$CCN_HOME/$JAR_FILE" ]
then
    if [ -f "$SCRIPT_DIR/../lib/$JAR_FILE" ] 
    then
	CCN_HOME="$SCRIPT_DIR/.."
    elif [ -f "$SCRIPT_DIR/../../../lib/$JAR_FILE" ]
    then
        CCN_HOME="$SCRIPT_DIR/../../.."
    else
	echo "Cannot find $JAR_FILE, set CCN_HOME env variable."
	exit 1;
    fi
fi

CP1=$SCRIPT_DIR/../ccnFileProxy.jar
CP2=$CCN_HOME/lib/*.jar

CP1=`echo $CP1 | sed "s/ /:/g"`
CP2=`echo $CP2 | sed "s/ /:/g"`

CLASSPATH=$CP1:$CP2
PORTARG=

if [ ! "$CCN_LOCAL_PORT" = "" ]; then
  PORTARG="-Dccn.agent.port=$CCN_LOCAL_PORT"
fi

if [ $# = 0 ]
then
  echo "usage: $0 <file path to serve> [<ccn prefix URI (default ccnx:/)>]"
  exit 1
fi

$JAVA -cp $CLASSPATH $PORTARG org.ccnx.ccn.apps.ccnfileproxy.CCNFileProxy $*


